    //初始化查询条件
    $(function(){
        getStudentList(1,10);
    });

    //学员分页对象
    let pageInfoList = new Vue({
        el: '#dataBody',
        data: {
            loading : true,
            studentList: [ /** @description 学员分页列表 */
            ],
            roleId : {

            },
            userId : {

            },
            storesId : {

            }
        },
        created:function(){
            this.loading = true;
        },
        watch:{
            studentList:function(){
                this.$nextTick(function(){
                    //根据分辨率大小隐藏单元格
                    let obj=$(".table");
                    if (!obj.hasClass("footable")) {
                        obj.addClass("footable");
                    }
                    $('.footable').footable();
                    $("#loading td:gt(0)").remove();
                    //console.log(new Date().getTime());
                });
            }
        },
        methods: {

            dialing(item) {
                call(item.phone,item.personId);
            },
            sms(item){
                sendSms(item.personId,item.phone,this.userId);
            },
            check(obj){
                 if($("input[name='checkBoxName']").length == $("input[name='checkBoxName']:checked").length){
                     $("#checkBoxAll").prop("checked", true);
                 }else{
                      $("#checkBoxAll").prop("checked", false);
                 }
            }
        }
    });
    //其画报  弹窗
    function call(phone,id){
        var html = '<div style="font-size: 15px">请选择接听方式</div>';
        html +='<div class="layui-form-item" style=" margin-top: 12px;margin-left: 10px;">' ;
        html += '<button class="layui-btn layui-btn-normal layui-btn-sm" id="saveViod" lay-submit="" lay-filter="demo1" onclick="callOut(\''+phone+'\',1)">手机接听</button>' ;
        html +='<button class="layui-btn layui-btn-warm layui-btn-sm" id="saveViod2" lay-submit="" lay-filter="demo1" onclick="callOut(\''+phone+'\',2)">企话宝接听</button>' ;
        html +='<button style="margin-top: 9%;margin-left: 28%;" type="reset" class="layui-btn layui-btn-primary layui-btn-sm" onclick="layer.closeAll()">稍后再拨</button>' ;
        html += '</div>' ;
        layer.tips(html, '#dialing'+id, {
            time : false,
            tips: [1, '#78BA32']
        });
    }

    //学员全选
    function checkBoxAll(obj) {
        if($(obj).is(":checked")){
            $("input[name='checkBoxName']").prop("checked",true);
        }else{
            $("input[name='checkBoxName']").prop("checked",false);
        }
    }

    //装变量的容器,可以使用多个分页器哦!
    let dataObj = {
        page_enterprise : 1,
        limit_enterprise: 10,
    };

    $(".registerSort i").click(function(){
        let sort = $(this).attr("data-sort");
        $(".releaseSort i").show();
        //console.info(sort);
        if(sort == 1){
            $(this).hide();
            $(this).next().show();
            $("#orderByClause").val("p.register_time asc");
        }else{
            $(this).hide();
            $(this).prev().show();
            $("#orderByClause").val("p.register_time desc");
        }
        getParamter();
        pageInfoList.studentList = [];
        getStudentList(1,dataObj.limit_enterprise);
    });

    $(".releaseSort i").click(function(){
        var sort = $(this).attr("data-sort");
        $(".registerSort i").show();
        //console.info(sort);
        if(sort == 1){
            $(this).hide();
            $(this).next().show();
            $("#orderByClause").val("p.release_time asc");
        }else{
            $(this).hide();
            $(this).prev().show();
            $("#orderByClause").val("p.release_time desc");
        }
        getParamter();
        pageInfoList.studentList = [];
        getStudentList(1,dataObj.limit_enterprise);
    });


    //鼠标经过事件  顺序
    function  down(obj){
        $(obj).css("cursor","Pointer");
        $(obj).attr("title","顺序排列")
    }

    //鼠标经过事件  倒序
    function up(obj){
        $(obj).css("cursor","Pointer");
        $(obj).attr("title","倒序排列")
    }
    //电话号码 ** 替换
    function phoneFormat(phone) {
        return phone.replace(phone.substring(7, 11), "****");
    }
    //时间格式化
    function add0(m){return m<10?'0'+m:m }
    function format(shijianchuo){
        if(shijianchuo == undefined ){
           return '';
        }
        //shijianchuo是整数，否则要parseInt转换
        var time = new Date(shijianchuo);
        var y = time.getFullYear();
        var m = time.getMonth()+1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
    }

    //打电话
     /**
     * 接听方式选择
     * @param phone
     * @param id
     * @returns
     */
    function call(phone,id){
        var html = '<div style="font-size: 15px">请选择接听方式</div>';
        html +='<div class="layui-form-item" style=" margin-top: 12px;margin-left: 10px;">' ;
        html += '<button class="layui-btn layui-btn-normal layui-btn-sm" id="saveViod" lay-submit="" lay-filter="demo1" onclick="callOut(\''+phone+'\',1)">手机接听</button>' ;
        html +='<button class="layui-btn layui-btn-warm layui-btn-sm" id="saveViod2" lay-submit="" lay-filter="demo1" onclick="callOut(\''+phone+'\',2)">企话宝接听</button>' ;
        html +='<button style="margin-top: 9%;margin-left: 28%;" type="reset" class="layui-btn layui-btn-primary layui-btn-sm" onclick="layer.closeAll()">稍后再拨</button>' ;
        html += '</div>' ;
        layer.tips(html, '#dialing'+id, {
            time : false,
            tips: [1, '#78BA32']
        });
    }

    var paramterObj = {

    };

    //获取学员列表数据
    function getStudentList(page,limit) {
        pageInfoList.studentList = [];
        paramterObj.page = page;
        paramterObj.limit = limit;
        dataObj.limit_enterprise=limit;
        dataObj.page_enterprise= page;
        $("#loading").show();
        $.ajax({
            type:'post',
            url:'/personCtl/getStudentList',
            data :JSON.stringify(paramterObj),
            cache:false,
            contentType:"application/json;charset=utf-8",
            dataType:'json',
            success:function(data){
                if(data.code>0){
                    console.info(data);
                    //店铺分类列表
                    pageInfoList.studentList = data.studentList;
                    pageInfoList.roleId = data.roleId;
                    pageInfoList.userId = data.userId;
                    pageInfoList.storesId = data.storesId;
                    let total = data.total;
                    $("#loading").hide();
                    layui.use(['laypage'], function(){
                      let laypage = layui.laypage;
                       //完整功能
                      laypage.render({
                       elem: 'page',
                       count: total,
                       limit: dataObj.limit_enterprise,
                       first: '首页',
                       last: '尾页',
                       loading: true, //翻页加loading
                       layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
                       curr: dataObj.page_enterprise,
                       theme: '#00A0E9',
                       jump: function(obj, first){
                            if(!first) {
                                dataObj.page_enterprise = obj.curr;
                                dataObj.limit_enterprise= obj.limit;
                                $("#loading").show();
                                pageInfoList.studentList = [];
                                getStudentList(obj.curr,obj.limit);
                            }
                        }
                      });
                   });

                }else{
                    layer.msg("请求失败",{icon: 2});
                }
            }
        });
    }

    //搜索
    function clickSearch() {
        getParamter();
        pageInfoList.studentList = [];
        getStudentList(1,dataObj.limit_enterprise);
    }
    
    //导出excel
    function exportExcel() {
        getParamter();
        // console.log("导出excel参数："+JSON.stringify(paramterObj));
        $.ajax({
            type:'post',
            url:'/personCtl/getExcelParam',
            data :JSON.stringify(paramterObj),
            cache:false,
            contentType:"application/json;charset=utf-8",
            dataType:'json',
            success:function(data){
                if(data.code === 1){
                    window.location.href = '/personCtl/exportExcel?key='+data.key;
                }
            },
            error : function(xhr, type, exception) {
              layer.msg(xhr.responseText, "Failed",{icon: 2});
            }
        });
    }

    function getParamter() {
        paramterObj.storeList = [];
        //店铺id 多选
        var stroreDom = $("input[name='stroresIds']:checked");
        for(var i = 0;i<stroreDom.length;i++){
            paramterObj.storeList.push($(stroreDom[i]).val());
        }
        let orderByClause=$("select[name='orderByClause']").val();
        if (orderByClause!=''){
            paramterObj.orderByClause = orderByClause;
        }else {
            paramterObj.orderByClause = $("#orderByClause").val();
        }

        //ccid  多选
        paramterObj.ccIds = [];
        var ccDom = $("input[name='ccIds']:checked");
        for(var i = 0;i<ccDom.length;i++){
            paramterObj.ccIds.push($(ccDom[i]).val());
        }
        //sscId
        if($("#sscId")){
             paramterObj.sscId = $("#sscId").val();
        }
        //bccId
        // paramterObj.bccId = $("#bccId").val();
        //学管师
        paramterObj.ltList = $("#ltId").val();
        //promotionId 活动
        paramterObj.promotionId = $("#promotionId").val();
        //客户属性列表
        paramterObj.stateIds = [];
        let stateDom = $("input[name='state']:checked");
        for(let i = 0;i<stateDom.length;i++){
            paramterObj.stateIds.push($(stateDom[i]).val());
        }
        //attendClassStores 上课店铺
        paramterObj.attendClassStores = $("#attendClassStores").val();
        //是否到店
        paramterObj.intention = $("#intention").val();
        //客户渠道
        paramterObj.listSourceId = [];
        var channelIdDom = $("input[name='channelIds']:checked");
        for(var i = 0;i<channelIdDom.length;i++){
            paramterObj.listSourceId.push(parseInt($(channelIdDom[i]).val()));
        }

        //年级多选
        if ($('#gradeIds').val()!==""){
            paramterObj.gradeIds=$('#gradeIds').val();
        }
        //线下店demo
        paramterObj.classStores = $("#classStores").val();

        //学校
        paramterObj.schoolId = $("#selectPage").val();
        //testmark
        paramterObj.testmark = $("#testmark").val();

        //注册开始时间
        paramterObj.registerStartTime = $("#registerStartTime").val();
        //注册结束时间
        paramterObj.registerEndTime = $("#registerEndTime").val();

        //上课开始时间
        paramterObj.releaseStartTime = $("#releaseStartTime").val();
        //上课结束时间
        paramterObj.releaseEndTime = $("#releaseEndTime").val();

        //未发布动态开始时间
        paramterObj.dynamicsPublishStartTime = $("#dynamicsPublishStartTime").val();
        //未发布动态结束时间
        paramterObj.dynamicsPublishEndTime = $("#dynamicsPublishEndTime").val();

        //有发布动态开始时间
        paramterObj.dynamicsStartTime=$("#dynamicsStartTime").val();
        //有发布动态结束时间
        paramterObj.dynamicsEndTime=$("#dynamicsEndTime").val();
        //cc变更开始日期
        paramterObj.ccChangeStartTime = $("#ccChangeStartTime").val();
        //cc变更结束日期
        paramterObj.ccChangeEndTime = $("#ccChangeEndTime").val();

        //订单到期开始日期
        paramterObj.surplusStartTime=$("#surplusStartTime").val();
        //订单到期开始日期
        paramterObj.surplusEndTime=$("#surplusEndTime").val();

        //searchId
        paramterObj.searchId = $("#searchId").val();
        //search
        paramterObj.search = $("#search").val();
        console.info(paramterObj);
    }

    //抢单按钮
    function setCCHtml(id,studentLogin,phone) {
        $("[rel=popover]").popover('destroy');
        $("#getpopover"+id).attr("disabled",true);
        let dataTitle='<h4>确认要抢吗？</h4>';
        let dataContent='<div style="text-align: center;">';
        dataContent+='<button type="button" class="btn btn-default" onclick="$(\'#getpopover'+id+'\').popover(\'destroy\');$(\'#getpopover'+id+'\').attr(\'disabled\',false);">不抢</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        dataContent+='<button type="button" class="btn btn-danger" id="getsure" onclick="setCCAjax('+id+',\''+studentLogin+'\',\''+phone+'\');">立即抢</button></div>';
        dataContent+='<div style="text-align: center;">';
        dataContent+='<div style="text-align: center;margin: 5px auto;">短信告知：<label class="radio-inline"><input type="radio" name="isSms" value="0" checked onclick="$(\'#divRemindTime\').hide();$(\'#remindTime\').val(\'\');">否</label> ' +
            '<label class="radio-inline" style="margin-left: 5px;"><input name="isSms" type="radio" value="1" onclick="$(\'#divRemindTime\').show();$(\'#remindTime\').focus();">是</label></div>';
        dataContent+='<div id="divRemindTime" style="text-align: center;display: none;"><input class="form-control input-sm" placeholder="请设置联系时间" name="remindTime" id="remindTime" readonly maxlength="20" autocomplete="off" title="请设置联系时间" onfocus="WdatePicker({dateFmt: \'yyyy-MM-dd HH:mm:00\', isShowToday: true, isShowClear: true,minDate:\'%y-%M-%d %H:{%m+3}:%s\'})"></div>';
        dataContent+='</div>';
        $("#getpopover"+id).popover({
            html : true ,
            title: dataTitle,
            content: dataContent,
            placement: 'left'
        });
        $("#getpopover"+id).popover("show");
        /*$("#getpopover"+id).next().css("top","180.703px").css("left","1555.5px");
        $("#getpopover"+id).next().find(".popover-content").css("line-height","45px");*/
        let mycount=setInterval(function(){$("#getpopover"+id).popover('destroy'); clearTimeout(mycount);$("#getpopover"+id).attr("disabled",false);},3000*20);

    }

    //提交抢单请求
    function setCCAjax(id,studentLogin,phone) {
        $("#getsure").attr("disabled",true);
        let isSms=$("input[name='isSms']:checked").val();
        let remindTime=$('#remindTime').val();
        if (isSms==="1"){
            if (""===remindTime){
                layer.msg("请设置联系时间！",{icon: 2});
                return false;
            }
        }
        $.ajax({
            type:'post',
            url:'/personCtl/setCC',
            data:{'id' : id,"isSms":isSms,"contactTime":remindTime,"phone":phone,"studentLogin":studentLogin},
            cache:false,
            async: false,
            dataType:'json',
            success:function(data){
                if(data.code === 1){
                    layer.msg("抢单成功",{icon: 1});
                    setTimeout(function() {
                        // window.location.reload();
                        //更新列表数据
                        getStudentList(dataObj.page_enterprise,dataObj.limit_enterprise);
                    },2500)
                }else if(data.code === -1){
                    layer.msg("您今天抢单已达到限制，请明天再来",{icon: 2});
                }else{
                    layer.msg("抢单失败,可能已被抢单，请刷新页面重试",{icon: 2});
                }
            },
            error : function(xhr, type, exception) {
              $("#getpopover"+id).attr("disabled",false);
              layer.msg(xhr.responseText, "Failed",{icon: 2});
            }
        });
    }

    //pcp学习计划表
	function pcp(personId){
		var url = "/PcpCtl/toPcp?personId="+personId;
		layer.open({
			// id: 'insert-form',
			type: 2,
			title: "",
			closeBtn: 1, //显示关闭按钮
			shade: [0.5],
			area: ['1020px', '98%'],
			// offset: 'rb', //右下角弹出
			// time: 2000, //2秒后自动关闭
			maxmin: false, //开启最大化最小化按钮
			anim: 2,
			content: [url, 'yes'], //iframe的url，no代表不显示滚动条

		});
	}

    /**
     * 学员基本信息卡片弹窗
      * @param personId  学员id
     */
    function personInfo(personId){
        if(personId==null || personId === ''){
            layer.msg("参数错误");
            return;
        }
        let url = '/student/info?personId='+personId;
        layer.open({
            id: 'insert-form',
            type: 2,
            title: "",
            closeBtn: 1, //显示关闭按钮
            shade: [0.5],
            area: ['98%', '99%'],
            // offset: 'rb', //右下角弹出
            // time: 2000, //2秒后自动关闭
            // maxmin: true, //开启最大化最小化按钮
            anim: 2,
            content: [url, 'no'], //iframe的url，no代表不显示滚动条
            end: function (index, layer) { //此处用于演示

            }
        });
    }

    /**
     * 学员基本信息卡片弹窗
      * @param personId  学员id
     */
    function stuDynamic(personId){
        if(personId==null || personId == ''){
            layer.msg("参数错误",{icon: 2});
            return;
        }
        var url = '/stuDynamic/dynamic?personId='+personId;
        layer.open({
                id: 'insert-form',
                type: 2,
                title: "",
                closeBtn: 1, //显示关闭按钮
                shade: [0.5],
                area: ['80%', '98%'],
                // offset: 'rb', //右下角弹出
                // time: 2000, //2秒后自动关闭
                maxmin: true, //开启最大化最小化按钮
                anim: 2,
                content: [url, 'yes'], //iframe的url，no代表不显示滚动条
                end: function (index, layer) { //此处用于演示

                }
        });
    }

    //预约课程
    function viewBooking(personId){
        $.ajax({
            type:'post',
            url:'/personCtl/getTokenString',
            data:{'id' : personId},
            cache:false,
            async: false,
            dataType:'json',
            success:function(data){
                if(data.code == 1){
                    var tokenString = data.student.tokenString;
                    layer.open({
                        type: 2 //Page层类型
                        ,area: ['95%','95%']
                        ,title: ''
                        ,shade: 0.6 //遮罩透明度
                        ,maxmin: false //允许全屏最小化
                        ,anim: 1 //0-6的动画形式，-1不开启
                        ,content: '/student/booked/course/'+personId+'?tokenString='+tokenString
                        ,cancel: function(){
                            // getBookedList(personId,1);
                        }
                    });
                }else{
                    layer.msg("请求失败",{icon: 2});
                }
            },
            error : function(xhr, type, exception) {
              $("#getpopover"+id).attr("disabled",false);
              layer.msg(xhr.responseText, "Failed",{icon: 2});
            }
        });
    }

    //变更cc按钮,flag: 区分 转单 还是 变更cc
    function changeCCHtml(id,flag) {
        $.ajax({
            type:'post',
            url:'/personCtl/ccList',
            cache:false,
            dataType:'json',
            data:{"flag" : flag},
            success:function(data){
                if(data.code == 1){
                    cchtml(id,data.ccList,flag);
                }else{
                    layer.msg("请求失败",{icon: 2});
                }
           },
        });
    }
    // 转单  弹窗
    function cchtml(id,listcc,flag){
        $("[rel=popover]").popover('destroy');
        let dataContent='<div style="text-align: center;">';
        dataContent+='<select class="form-control" id="userid"><option value="">选择课程顾问</option>';
        if(listcc!=null && listcc.length>0){
            for(var i=0;i<listcc.length;i++){
                dataContent+='<option  value="'+listcc[i].id+'">'+listcc[i].loginName+'</option>';
            }
        }
        dataContent+='</select>';
        dataContent+='</div>';
        dataContent+='<div style="text-align: center;">';
        dataContent+='<button type="button" class="btn btn-default" onclick="$(\'#changepopover'+id+flag+'\').popover(\'destroy\');$(\'#changepopover'+id+flag+'\').attr(\'disabled\',false);">取消</button>&nbsp;&nbsp;';
        dataContent+='<button type="button" id="changesure" class="btn btn-danger" onclick="changeCCAjax('+id+','+flag+')">立即变更</button><div>';
        var dataTitle='<h4>请选择新的课程顾问</h4>';
        $("#changepopover"+id+flag).popover({
            html : true ,
            title: dataTitle,
            content: dataContent,
            placement: 'left'
        });
        $("#changepopover"+id+flag).popover("show");
        $("#changepopover"+id+flag).next().find(".popover-content").css("line-height","45px");
    }
    //提交  转单、变更请求
    function changeCCAjax(id,flag){
        if($("#userid").val()==null || $("#userid").val()==""){
            layer.msg("请选择要变更的cc",{icon: 2});
            return;
        }
        $("#changepopover"+id+flag).attr("disabled",true);
        $("#changesure").attr("disabled",true);
        $.ajax({
            type:'post',
            url:'/personCtl/changeCc',
            data:{'personId' : id,'ccId':$("#userid").val(),"type":flag},
            cache:false,
            dataType:'json',
            success:function(data){
                if(data.code > 0){
                    if(flag == 0){
                        layer.msg("变更cc成功",{icon: 1});
                    }else if(flag == 1){
                        layer.msg("转单成功",{icon: 1});
                    }
                    setTimeout(function () {
                        getStudentList(dataObj.page_enterprise,dataObj.limit_enterprise);
                    },2500);
                }else{
                    layer.msg("变更cc失败",{icon: 2});
                }
           },
            error : function(xhr, type, exception) {
              alert(xhr.responseText, "Failed");
             }
        });
    }

    //删除学员
    function popoverHtml(id) {
        $("[rel=popover]").popover('destroy');
        var dataContent='<div style="text-align: center;">';
        dataContent+='<button type="button" class="btn btn-default" onclick="$(\'#popover'+id+'\').popover(\'destroy\');">取消</button>&nbsp;&nbsp;';
        dataContent+='<button type="button" class="btn btn-danger" onclick="delPerson('+id+')">确认</button><div>';
        var dataTitle='<h4>确认要删除本用户吗？</h4>';
        $("#delpopover"+id).popover({
            html : true ,
            title: dataTitle,
            content: dataContent,
            placement: 'left'
        });
        $("#delpopover"+id).popover("show");
        var mycount=setInterval(function(){$("#delpopover"+id).popover('destroy'); clearTimeout(mycount)},3000);
    }

    //提交  学员 删除请求
    function delPerson(id){
	    $("[rel=popover]").popover('destroy');
        $.ajax({
            type:'post',
            url:'/personCtl/delPerson',
            data:{'personId' : id},
            cache:false,
            dataType:'json',
            success:function(data){
                if(data.code > 0){
                    layer.msg("删除成功",{icon: 1});
                    setTimeout(function () {
                        getStudentList(dataObj.page_enterprise,dataObj.limit_enterprise);
                    },2500);
                }else{
                    layer.msg("删除失败",{icon: 2});
                }
           },
        });
    }

    //批量修改关联cc窗口
    function viewModalComplain() {
        var dom = $("input[name='checkBoxName']:checked");
        if(dom.length == 0){
           layer.msg("请选择学员",{icon: 2});
           return;
        }
        var strIds = "";
        for(var i = 0;i<dom.length;i++){
            if(i == dom.length-1 || dom.length== 1){
                strIds+=$(dom[i]).val();
            }else{
                strIds+=$(dom[i]).val()+",";
            }
        }
        let url = '/personCtl/toCcSscBccList?strIds='+strIds;
        layer.open({
            id: 'insert-form',
            type: 2,
            title: "",
            closeBtn: 1, //显示关闭按钮
            shade: [0.5],
            area: ['400px', '400px'],
            // offset: 'rb', //右下角弹出
            // time: 2000, //2秒后自动关闭
            maxmin: false, //开启最大化最小化按钮
            anim: 2,
            // shadeClose: false, //点击遮罩关闭
            // scrollbar: false, // 父页面 滚动条 禁止
            content: [url, 'yes'], //iframe的url，no代表不显示滚动条
            end: function (index, layer) { //此处用于演示

            }
        });
    }

    function toEditPerson(personId) {
        if(personId == undefined || personId == ''){
            layer.msg("参数错误",{icon: 2});
            return
        }
        let url = '/student/info/edit?personId='+personId;
		layer.open({
			// id: 'insert-form',
			type: 2,
			title: "",
			closeBtn: 1, //显示关闭按钮
			shade: [0.5],
			area: ['80%', '98%'],
			// offset: 'rb', //右下角弹出
			// time: 2000, //2秒后自动关闭
			maxmin: false, //开启最大化最小化按钮
			anim: 2,
			content: [url, 'yes'], //iframe的url，no代表不显示滚动条

		});
    }

    function toAddPerson() {
        let url = '/student/info/toAddPerson';
		layer.open({
			// id: 'insert-form',
			type: 2,
			title: "",
			closeBtn: 1, //显示关闭按钮
			shade: [0.5],
			area: ['80%', '98%'],
			// offset: 'rb', //右下角弹出
			// time: 2000, //2秒后自动关闭
			maxmin: false, //开启最大化最小化按钮
			anim: 2,
			content: [url, 'yes'], //iframe的url，no代表不显示滚动条

		});
    }

    //奖学金申请
    function scholarshipHtml(id) {
        $("[rel=popover]").popover('destroy');
        $("#scholarship"+id).attr("disabled",true);
        let dataTitle='<h4>申请奖学金</h4>';
        let dataContent='<div style="text-align: center;">';
        dataContent+="<div style='text-align: center;font-size: 16px;padding-bottom: 10px;'>请确认已提交相关资料</div>";
        dataContent+='<button type="button" class="btn btn-default" onclick="$(\'#scholarship'+id+'\').popover(\'destroy\');$(\'#scholarship'+id+'\').attr(\'disabled\',false);">暂不申请</button>&nbsp;&nbsp;';
        dataContent+='<button type="button" class="btn btn-danger" id="getsure" onclick="setScholarship('+id+');">立即申请</button><div>';
        $("#scholarship"+id).popover({
            html : true ,
            title: dataTitle,
            content: dataContent,
            placement: 'left'
        });
        $("#scholarship"+id).popover("show");
    }

    //提交奖学金申请
    function setScholarship(id) {
        $.ajax({
            type:'post',
            url:'/personCtl/addScholarship',
            data:{'personId' : id},
            cache:false,
            dataType:'json',
            success:function(data){
                if(data.code == 1){
                    layer.msg("奖学金申请成功",{icon: 1});
                    $('#scholarship'+id).text("奖学金(审核中)");
                    $('#scholarship'+id).attr("onclick","");
                    $("#scholarship"+id).popover('destroy');
                }else if(data.code == -1){
                    layer.msg("参数错误，请联系管理员",{icon: 2});
                }else{
                    layer.msg("奖学金申请失败",{icon: 2});
                }
           },
        });
    }

    //奖学金申请通过查看
    function getScholarshipHtml(obj) {
        let jqobj=$(obj);
        let id = jqobj.data("personid");
        let name = jqobj.data("cnname") == ''?jqobj.data("loginname"):jqobj.data("cnname");
        $.ajax({
            type:'post',
            url:'/personCtl/getScholarship',
            data:{'personId' : id},
            cache:false,
            dataType:'json',
            success:function(data){
                if (data.code == 1) {
                    $("[rel=popover]").popover('destroy');
                    $("#scholarship"+id).attr("disabled",true);
                    let dataTitle='<h4>申请奖学金结果</h4>';
                    let dataContent='<div style="text-align: center;">';
                    dataContent+="<div style='text-align: center;font-size: 16px;padding-bottom: 10px;'><a href='javascript:' onclick='isPayMoney("+id+")'>恭喜您，已获得"+data.scholarship+"元奖学金</a></div>";
                    dataContent+='<button type="button" class="btn btn-default" onclick="$(\'#scholarship'+id+'\').popover(\'destroy\');$(\'#scholarship'+id+'\').attr(\'disabled\',false);">关闭</button>&nbsp;&nbsp;';
                    dataContent+='<button type="button" class="btn btn-default" onclick="createCert(\''+name+'\','+data.scholarship+',\''+data.createTime+'\');$(\'#scholarship'+id+'\').popover(\'destroy\');$(\'#scholarship'+id+'\').attr(\'disabled\',false);">查看证书</button>&nbsp;&nbsp;';
                    dataContent+='<div>';
                    $("#scholarship"+id).popover({
                        html : true ,
                        title: dataTitle,
                        content: dataContent,
                        placement: 'left'
                    });
                    $("#scholarship"+id).popover("show");
                }else if(data.code == -1){
                    layer.msg("参数错误，请联系管理员",{icon: 2});
                }else{
                    layer.msg("请求失败",{icon: 2});
                }
            }
        });
    }

    //奖学金申请通过查看,不可编辑
    function viewScholarshipHtml(obj) {
        let jqobj=$(obj);
        let id = jqobj.data("personid");
        let name = jqobj.data("cnname") == ''?jqobj.data("loginname"):jqobj.data("cnname");
        $.ajax({
            type:'post',
            url:'/personCtl/getScholarship',
            data:{'personId' : id},
            cache:false,
            dataType:'json',
            success:function(data){
                if(data.code == 1){
                    $("[rel=popover]").popover('destroy');
                    $("#scholarship"+id).attr("disabled",true);
                    let dataTitle='<h4>申请奖学金结果</h4>';
                    let dataContent='<div style="text-align: center;">';
                    dataContent+="<div style='text-align: center;font-size: 16px;padding-bottom: 10px;'>恭喜您，已获得"+data.scholarship+"元奖学金</div>";
                    dataContent+='<button type="button" class="btn btn-default" onclick="$(\'#scholarship'+id+'\').popover(\'destroy\');$(\'#scholarship'+id+'\').attr(\'disabled\',false);">关闭</button>&nbsp;&nbsp;';
                    dataContent+='<button type="button" class="btn btn-default" onclick="createCert(\''+name+'\','+data.scholarship+',\''+data.createTime+'\');$(\'#scholarship'+id+'\').popover(\'destroy\');$(\'#scholarship'+id+'\').attr(\'disabled\',false);">查看证书</button>&nbsp;&nbsp;';
                    dataContent+='<div>';
                    $("#scholarship"+id).popover({
                        html : true ,
                        title: dataTitle,
                        content: dataContent,
                        placement: 'left'
                    });
                    $("#scholarship"+id).popover("show");
                }else if(data.code == -1){
                    layer.msg("参数错误，请联系管理员",{icon: 2});
                }else{
                    layer.msg("奖学金申请失败",{icon: 2});
                }
           },
        });
        let mycount=setInterval(function(){$("#scholarship"+id).popover('destroy'); clearTimeout(mycount);$("#scholarship"+id).attr("disabled",false);},6000);
    }

    //查看证书
    function createCert(name,money,dates) {
        layer.open({
            type: 2,
            title: '',
            shadeClose: false,
            shade: 0.8,
            area: ['600px', '90%'],
            content: "/personCtl/cert?name="+name+"&money="+money+"&dates="+dates
        });
    }

    function isPayMoney(id) {
        layer.confirm('是否确认支付定金保留名额？', {
          btn: ['是','否'] //按钮
          ,cancel: function(index, layero){
            //取消操作，点击右上角的X
          }
        }, function(){
            $.post("/personCtl/payMoney",{"personId":id},function (result) {
                if (result.code == 1){
                    $('#scholarship'+id).attr("disabled",false);
                    $('#scholarship'+id).text("奖学金(已保留)");
                    $('#scholarship'+id).attr("onclick","viewScholarshipHtml("+id+")");
                }else if(data.code == -1){
                    layer.msg("参数错误，请联系管理员",{icon: 2});
                }else{
                    layer.msg("保留名额失败，请重试或与管理员练习",{icon: 2});
                }
            });
        }, function(){
             $('#scholarship'+id).attr("disabled",false);
        });
        $("#scholarship"+id).popover('destroy');
    }
